package io.github.lostblackknight;

import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;

/**
 * @author chensixiang chensixiang1234@gmail.com
 */
public class JedisDemo1 {

    Jedis jedis = new Jedis("192.168.255.133", 6379);

    @Test
    public void test1() {
        System.out.println("jedis.ping() = " + jedis.ping());
    }

    @Test
    public void test2() {
        jedis.keys("*").forEach(System.out::println);
    }

    @Test
    public void test3() {
        String flushDB = jedis.flushDB();
        System.out.println(flushDB);
    }

    @Test
    public void test4() {
        jedis.set("name","lucy");
        jedis.expire("name", 30L);
        System.out.println(jedis.get("name"));
        System.out.println(jedis.ttl("name"));
    }

    @Test
    public void test5() {
        jedis.mset("k1","v1","k2","v2");
        List<String> res = jedis.mget("k1", "k2");
        res.forEach(System.out::println);
    }

    @Test
    public void test6() {
        jedis.lpush("key1","lucy","mary","jack");
        List<String> res = jedis.lrange("key1", 0, -1);
        res.forEach(System.out::println);
    }

    @Test
    public void test7() {
        jedis.sadd("name","lucy","jack","jack");
        Set<String> name = jedis.smembers("name");
        name.forEach(System.out::println);
    }

    @Test
    public void test8() {
        jedis.hset("user","age","20");
        String hget = jedis.hget("user", "age");
        System.out.println(hget);
    }

    @Test
    public void test9() {
        jedis.zadd("china",100.0,"zhanghai");
        Set<String> china = jedis.zrange("china", 0, -1);
        china.forEach(System.out::println);
    }
}
